using RpgXna.Model.Entities;

namespace RpgXna.Model.Interfaces.ContextMenu.InteractionBehaviors
{
    class PickUpItemContextMenuBehavior : ContextMenuItem
    {
        private readonly PickableObject _targetObject;
        private readonly Inventory.Inventory _inventory;
        private readonly EnvironmentRepository _environment;

        public PickUpItemContextMenuBehavior(PickableObject targetObject, Inventory.Inventory inventory, EnvironmentRepository environment)
        {
            _targetObject = targetObject;
            _inventory = inventory;
            _environment = environment;
            Action = InternalExecute;
            ItemName = "Ramasser";
        }


        void InternalExecute()
        {
            //check if the invetory has enought space to store the item and add it if it's the case
            if (_inventory.Add(_targetObject))
            {
                //...and thus remove the item from the environment
                _environment.Remove(_targetObject);
            }
        }
    }
}